package mess;

import java.util.HashMap;
import java.util.Map;

public class LeeCode_2325 {
    public static void main(String[] args) {
        String key = "the quick brown fox jumps over the lazy dog";
        String message = "vkbs bs t suepuv";
        System.out.println(decodeMessage(key, message));
    }
    private static String decodeMessage(String key, String message) {
        Map<Character, Character> keys = new HashMap<>();
        int cNum = 'a';
        for (int i = 0; i < key.length(); i++) {
            char c = key.charAt(i);
            if (c == ' ')
                continue;
            if (keys.containsKey(c))
                continue;
            keys.put(c, (char) cNum);
            cNum++;
        }
        System.out.println(keys);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < message.length(); i++) {
            char c = message.charAt(i);
            if (!keys.containsKey(c)) {
                sb.append(c);
                continue;
            }
            sb.append(keys.get(c));
        }
        return sb.toString();
    }
}
